<?php
Yii::app()->clientScript->registerCss('tareaObjetivo' . $model->id, '
.realizado
{   text-decoration: line-through;
}
.no_realizado{
text-decoration: none;
}
');
?>
<div class = "widget orange">
    <div class = "widget-title">
        <h4><i class = "icon-puzzle-piece"></i> Objetivos</h4>
        <span class = "tools">
            <a href = "javascript:;" class = "icon-chevron-down"></a>
            <a href="javascript:;" class="icon-remove"></a>
        </span>
    </div>
    <div class = "widget-body">
        <?php
        $modelTareaObjetivo = new TareaObjetivo();
        $modelTareaObjetivo->tarea_id = $model->id;
        $modelTareaObjetivo->realizado = 0;
        $form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(
            'id' => 'tarea-objetivo-form',
            'type' => 'vertical',
            'enableAjaxValidation' => true,
            'clientOptions' => array('validateOnSubmit' => false, 'validateOnChange' => false,),
            'enableClientValidation' => false,
        ));
        ?>

        <?php echo $form->textFieldRow($modelTareaObjetivo, 'objetivo', array('class' => 'span12', 'maxlength' => 254)) ?>
        <?php echo $form->hiddenField($modelTareaObjetivo, 'tarea_id') ?>
        <?php echo $form->hiddenField($modelTareaObjetivo, 'realizado') ?>


        <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'type' => 'success',
            'icon' => 'ok',
            'label' => $model->isNewRecord ? Yii::t('AweCrud.app', 'Create') : Yii::t('AweCrud.app', 'Save'),
            'htmlOptions' => array(
                'onclick' => 'js:guardarObjetivo("' . CController::createUrl('/tareas/tarea/guardarObjetivo') . '")',
            ),
        ))
        ?>

        <?php $this->endWidget(); ?>
        <br>
        <?php
        $this->widget(
                'bootstrap.widgets.TbProgress', array(
            'type' => 'success', // 'info', 'success' or 'danger'
            'percent' => $datos['porcentaje_no_realizadas'],
//            'striped' => true,
//            'animated' => true,
            'htmlOptions' => array(
                'id' => 'progresoObjetivo',
            )
                )
        );
        ?>
        <?php
        $modelTareaObjetivo->unsetAttributes();
        $modelTareaObjetivo->tarea_id = $model->id;
        $this->widget('ext.bootstrap.widgets.TbGridView', array(
            'id' => 'objetivo-grid',
//            'type' => 'striped bordered hover advance',
            'showTableOnEmpty' => false,
            'emptyText' => '',
            'selectableRows' => 2,
            "template" => "{items}{summary}{pager}",
            'hideHeader' => true,
            'dataProvider' => $modelTareaObjetivo->search(),
            'columns' => array(
//                'id',
                array(
                    'name' => 'realizado',
                    'class' => 'CCheckBoxColumn',
                    'value' => '$data->id',
                    'checked' => '$data->realizado',
                    'htmlOptions' => array(
                        'width' => '20px',
                    ),
                    'checkBoxHtmlOptions' => array(
                    )
                ),
                array(
                    'name' => 'objetivo',
                    'value' => '$data->objetivo',
                    'htmlOptions' => array(
                    ),
                    'cssClassExpression' => '$data->realizado?"realizado":"no_realizado"',
                    'type' => 'raw'
                ),
//                'objetivo',
//                'realizado',
                array(
                    'class' => 'CButtonColumn',
                    'afterDelete' => 'function(link,success,data){ 
                        $("#progresoObjetivo > div").attr("style", "width:" + data + "%"); 
                            }',
                    'template' => '{delete}',
                    'buttons' => array(
                        'delete' => array(
                            'url' => 'Yii::app()->createUrl("/tareas/tarea/deleteObjetivo", array("id"=>$data->id))',
                            'label' => '<button class="btn btn-danger"><i class="icon-trash"></i></button>',
                            'options' => array('title' => 'Eliminar'),
                            'imageUrl' => false,
//                            'visible' => 'Util::checkAccess(array("action_nota_delete"))'
                        ),
                    ),
                ),
            )
                )
        );
        ?>
    </div>
</div>